﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using DAL;

public class admin : IHttpHandler
{
    AdminDAL AD = new AdminDAL();
    public void ProcessRequest(HttpContext context)
    {
        string functionname = context.Request.Form["functionname"].ToString();
        switch (functionname)
        {
            //start 系统菜单设置部分#####################################

            //显示所有菜单
            case "jhy_menu_query": jhy_menu_query(); break;
            //显示所有菜单组
            case "jhy_menugroup_query": jhy_menugroup_query(); break;
            //添加菜单组
            case "jhy_menugroup_add": jhy_menugroup_add(); break;
            //删除菜单组
            case "jhy_menugroup_delete": jhy_menugroup_delete(); break;
            //修改菜单组
            case "jhy_menugroup_edit": jhy_menugroup_edit(); break;
            //添加菜单
            case "jhy_menu_add": jhy_menu_add(); break;
            //删除菜单
            case "jhy_menu_delete": jhy_menu_delete(); break;
            //修改菜单
            case "jhy_menu_edit": jhy_menu_edit(); break;
            //end 系统菜单设置部分#################################################
            //start 系统角色管理部分###############################################
            //查询系统角色
            case "jhy_role_query": jhy_role_query(); break;
            //添加系统角色
            case "jhy_role_add": jhy_role_add(); break;
            //删除系统角色
            case "jhy_role_delete": jhy_role_delete(); break;
            //修改系统角色
            case "jhy_role_edit": jhy_role_edit(); break;
            //查询系统角色菜单
            case "jhy_role_menu_query": jhy_role_menu_query(); break;
            //系统角色菜单管理
            case "jhy_role_menu_edit": jhy_role_menu_edit(); break;
            //end 系统角色管理部分###############################################
            //start 网站配置#####################################################
            //网站配置
            case "jhy_site_update": jhy_site_update(); break;
            //网站参数查询
            case "jhy_site_query": jhy_site_query(); break;
            //end 网站配置#######################################################
            //start 用户管理#####################################################

            //查询用户
            case "jhy_user_query": jhy_user_query(); break;
            //添加用户
            case "jhy_user_add": jhy_user_add(); break;
            //删除用户
            case "jhy_user_delete": jhy_user_delete(); break;
            //修改用户
            case "jhy_user_edit": jhy_user_edit(); break;
            //查询用户关联角色
            case "jhy_user_role_query": jhy_user_role_query(); break;
            //管理用户关联角色
            case "jhy_user_role_edit": jhy_user_role_edit(); break;
            //用户登录验证
            case "jhy_user_login": jhy_user_login(); break;
            //查询用户菜单
            case "jhy_user_menu": jhy_user_menu(); break;
            //用户修改密码
            case "jhy_user_edit_password": jhy_user_edit_password(); break;
            //end 用户管理#######################################################

            //start 访问记录
            //添加访问记录
            case "jhy_browsing_add": jhy_browsing_add(); break;
            //查询访问记录
            case "jhy_browsing_query": jhy_browsing_query(); break;
                //end 访问记录


        }
    }

    //start 系统菜单设置部分
    #region 显示所有菜单
    public void jhy_menu_query()
    {
        HttpContext.Current.Response.Write(AD.jhy_menu_query());
    }
    #endregion
    #region 显示所有菜单组
    public void jhy_menugroup_query()
    {
        HttpContext.Current.Response.Write(AD.jhy_menugroup_query());
    }
    #endregion
    #region 添加菜单组
    public void jhy_menugroup_add()
    {
        string mg_name = HttpContext.Current.Request.Form["mg_name"].ToString();
        bool b = AD.jhy_menugroup_add(mg_name);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 删除菜单组
    public void jhy_menugroup_delete()
    {
        string mg_id = HttpContext.Current.Request.Form["mg_id"].ToString();
        bool b = AD.jhy_menugroup_delete(mg_id);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 修改菜单组
    public void jhy_menugroup_edit()
    {
        string mg_id = HttpContext.Current.Request.Form["mg_id"].ToString();
        string mg_field = HttpContext.Current.Request.Form["mg_field"].ToString();
        string mg_para = HttpContext.Current.Request.Form["mg_para"].ToString();
        bool b = AD.jhy_menugroup_edit(mg_id, mg_field, mg_para);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 添加菜单
    public void jhy_menu_add()
    {
        string menu_name = HttpContext.Current.Request.Form["menu_name"].ToString();
        string menu_url = HttpContext.Current.Request.Form["menu_url"].ToString();
        string mg_id = HttpContext.Current.Request.Form["mg_id"].ToString();
        bool b = AD.jhy_menu_add(menu_name, menu_url, mg_id);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 删除菜单
    public void jhy_menu_delete()
    {
        string menu_id = HttpContext.Current.Request.Form["menu_id"].ToString();
        bool b = AD.jhy_menu_delete(menu_id);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 修改菜单
    public void jhy_menu_edit()
    {
        string menu_id = HttpContext.Current.Request.Form["menu_id"].ToString();
        string menu_field = HttpContext.Current.Request.Form["menu_field"].ToString();
        string menu_para = HttpContext.Current.Request.Form["menu_para"].ToString();
        bool b = AD.jhy_menu_edit(menu_id, menu_field, menu_para);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    //end 系统菜单设置部分
    //start 系统角色管理部分
    #region 查询系统角色
    public void jhy_role_query()
    {
        HttpContext.Current.Response.Write(AD.jhy_role_query());
    }
    #endregion
    #region 添加系统角色
    public void jhy_role_add()
    {
        string role_name = HttpContext.Current.Request.Form["role_name"].ToString();
        string role_level = HttpContext.Current.Request.Form["role_level"].ToString();
        bool b = AD.jhy_role_add(role_name, role_level);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 删除系统角色
    public void jhy_role_delete()
    {
        string role_id = HttpContext.Current.Request.Form["role_id"].ToString();
        bool b = AD.jhy_role_delete(role_id);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 修改系统角色
    public void jhy_role_edit()
    {
        string role_id = HttpContext.Current.Request.Form["role_id"].ToString();
        string role_field = HttpContext.Current.Request.Form["role_field"].ToString();
        string role_para = HttpContext.Current.Request.Form["role_para"].ToString();
        bool b = AD.jhy_role_edit(role_id, role_field, role_para);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 查询系统角色菜单
    public void jhy_role_menu_query()
    {
        string role_id = HttpContext.Current.Request.Form["role_id"].ToString();
        string role_field = HttpContext.Current.Request.Form["role_field"].ToString();
        DataSet ds = new DataSet();
        ds = AD.jhy_role_menu_query(role_id);
        QXHelper QX = new QXHelper();
        if (role_field == "true")
        {
            HttpContext.Current.Response.Write(QX.LayuiTableJson(ds.Tables[0]));
        }
        else
        {
            HttpContext.Current.Response.Write(QX.LayuiTableJson(ds.Tables[1]));
        }

    }
    #endregion
    #region 系统角色菜单管理
    public void jhy_role_menu_edit()
    {
        string role_id = HttpContext.Current.Request.Form["role_id"].ToString();
        string menu_id = HttpContext.Current.Request.Form["menu_id"].ToString();
        string field = HttpContext.Current.Request.Form["field"].ToString();
        bool b = AD.jhy_role_menu_edit(role_id, menu_id, field);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    //end 系统角色管理部分
    //start 网站配置
    #region 网站配置
    public void jhy_site_update()
    {
        string site_logotext = HttpContext.Current.Request.Form["site_logotext"].ToString();
        string site_logoicon = HttpContext.Current.Request.Form["site_logoicon"].ToString();
        string site_notice = HttpContext.Current.Request.Form["site_notice"].ToString();
        string site_copyright = HttpContext.Current.Request.Form["site_copyright"].ToString();
        string site_about = HttpContext.Current.Request.Form["site_about"].ToString();
        bool b = AD.jhy_site_update(site_logotext, site_logoicon, site_notice, site_copyright, site_about);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 网站参数查询
    public void jhy_site_query()
    {
        HttpContext.Current.Response.Write(AD.jhy_site_query());
    }
    #endregion
    //end 网站配置
    //start 用户管理
    #region 查询用户
    public void jhy_user_query()
    {
        HttpContext.Current.Response.Write(AD.jhy_user_query());
    }
    #endregion
    #region 添加用户
    public void jhy_user_add()
    {
        string user_account = HttpContext.Current.Request.Form["user_account"].ToString();
        string user_name = HttpContext.Current.Request.Form["user_name"].ToString();
        string user_password = HttpContext.Current.Request.Form["user_password"].ToString();
        bool b = AD.jhy_user_add(user_account, user_name, user_password);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 删除用户
    public void jhy_user_delete()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        bool b = AD.jhy_user_delete(user_id);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 修改用户
    public void jhy_user_edit()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        string user_field = HttpContext.Current.Request.Form["user_field"].ToString();
        string user_para = HttpContext.Current.Request.Form["user_para"].ToString();
        bool b = AD.jhy_user_edit(user_id, user_field, user_para);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 查询用户关联角色
    public void jhy_user_role_query()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        string user_field = HttpContext.Current.Request.Form["user_field"].ToString();
        DataSet ds = new DataSet();
        ds = AD.jhy_user_role_query(user_id);
        QXHelper QX = new QXHelper();
        if (user_field == "true")
        {
            HttpContext.Current.Response.Write(QX.LayuiTableJson(ds.Tables[0]));
        }
        else
        {
            HttpContext.Current.Response.Write(QX.LayuiTableJson(ds.Tables[1]));
        }
    }
    #endregion
    #region 管理用户关联角色
    public void jhy_user_role_edit()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        string role_id = HttpContext.Current.Request.Form["role_id"].ToString();
        string field = HttpContext.Current.Request.Form["field"].ToString();
        bool b = AD.jhy_user_role_edit(user_id, role_id, field);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    #region 用户登录验证
    public void jhy_user_login()
    {
        string user_account = HttpContext.Current.Request.Form["user_account"].ToString();
        string user_password = HttpContext.Current.Request.Form["user_password"].ToString();
        HttpContext.Current.Response.Write(AD.jhy_user_login(user_account, user_password));
    }
    #endregion
    #region 查询用户菜单
    public void jhy_user_menu()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        DataTable dt1 = new DataTable();
        DataTable dt2 = new DataTable();
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        ds1 = AD.jhy_user_menu(user_id, "");
        dt1 = ds1.Tables[0];
        if (dt1.Rows.Count > 0)
        {
            foreach (DataRow dr1 in dt1.Rows)
            {
                sb1.Append("<li class=\"layui-nav-item\">");
                sb1.Append("<a href = \"javascript:;\" >" + dr1["mg_name"].ToString() + "<span class=\"layui-nav-more\"></span></a>");
                sb1.Append("<dl class=\"layui-nav-child\">");
                ds2 = AD.jhy_user_menu(user_id, dr1["mg_id"].ToString());
                dt2 = ds2.Tables[1];
                foreach (DataRow dr2 in dt2.Rows)
                {
                    sb2.Append("<dd><a href = \"javascript:;\" jhy-url=\"" + dr2["menu_url"].ToString() + "\"> " + dr2["menu_name"].ToString() + "</a></dd>");
                }
                sb1.Append(sb2.ToString());
                sb1.Append("</dl>");
                sb1.Append("</li>");
                sb2.Clear();
            }
            HttpContext.Current.Response.Write(sb1.ToString());
        }
        else
        {
            HttpContext.Current.Response.Write("none");
        }

    }
    #endregion
    #region 用户修改密码
    public void jhy_user_edit_password()
    {
        string user_id = HttpContext.Current.Request.Form["user_id"].ToString();
        string user_password = HttpContext.Current.Request.Form["user_password"].ToString();
        bool b = AD.jhy_user_edit_password(user_id, user_password);
        if (b)
        {
            HttpContext.Current.Response.Write("true");
        }
        else
        {
            HttpContext.Current.Response.Write("false");
        }
    }
    #endregion
    //end 用户管理

    //start添加访问记录
    #region 添加访问记录
    public void jhy_browsing_add()
    {
        QXHelper QX = new QXHelper();
        string b_ip = QX.GetIP();
        string b_url = HttpContext.Current.Request.Form["b_url"].ToString();
        AD.jhy_browsing_add(b_ip, b_url);
    }
    #endregion
    #region 查询访问记录
    public void jhy_browsing_query()
    {
        string laypage = HttpContext.Current.Request.Form["page"].ToString();
        string laylimit = HttpContext.Current.Request.Form["limit"].ToString();
        HttpContext.Current.Response.Write(AD.jhy_browsing_query(laypage, laylimit));
    }
    #endregion
    //end添加访问记录
































    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}